package edu.ubbcluj.turisztikai.activity;

import java.util.StringTokenizer;

import turistic.GUI.graphic.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextSwitcher;
import android.widget.TextView;

public class RoutesActivity extends Activity  {
	private TextSwitcher mSwitcher;
	private TextSwitcher mSwitcherAllomasok;

	private int mCounter = 0;

	String[] korut = new String[] { "Kolozsvar-Torda" };
	String[] allomas = new String[] { "Kolozsvar" , "Torda" };
	String[] k = new String[] { "Matyas-szobor", "Botanikus Kert", "BBTE" };
	String[] t = new String[] { "Sobanya", "Tordai-Hasadek" };
	
	
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.routesview);
		
		
		
		
		Spinner s = (Spinner) findViewById(R.id.spinner1);
		s.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, korut));
		 
		final Spinner s1 = (Spinner) findViewById(R.id.spinner2);
		final Spinner s2 = (Spinner) findViewById(R.id.spinner3);

		//	s1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, myList1));
		final ArrayAdapter<String> a = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, allomas);
		s1.setAdapter(a);
		final ArrayAdapter<String> at = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, t);
		final ArrayAdapter<String> ak = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, k);
			
		s1.setOnItemSelectedListener(new OnItemSelectedListener(){

			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				if (position == 0)
					s2.setAdapter(ak);
				else
					s2.setAdapter(at);
							
				 //s1.setSelection(position);		
				
			}

			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub
				
			}

		});
		
		Button next = (Button) findViewById(R.id.nextB);
		next.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent sender = getIntent();
				String x = sender.getExtras().getString("Coordinates");
				String sor[][] = new String[3][2];
				StringTokenizer st = new StringTokenizer(x, " ");

				x = x + " 46.770255 " + "23.590189 " + "46.767415 " + "23.591613 " + "46.762392 "+ "23.589395 "+ "46.584144 " + "23.77685 "+ "46.563818 "+ "23.699913";// + "46.584144 " + "23.77685 " + "46.564201 " + "23.679249";//"46.771144";
				 //"23.602409";
				Intent intent = new Intent(RoutesActivity.this,
						SettingsActivity.class);
				intent.putExtra("Coordinates", x);

				startActivity(intent);

			}
		});
	}
	/*	mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
		mSwitcher.setFactory(this);
		
		mSwitcherAllomasok = (TextSwitcher) findViewById(R.id.tSAllomasok);
		mSwitcherAllomasok.setFactory(this);
		Animation in = AnimationUtils.loadAnimation(this,
				android.R.anim.fade_in);
		Animation out = AnimationUtils.loadAnimation(this,
				android.R.anim.fade_out);
		mSwitcher.setInAnimation(in);
		mSwitcher.setOutAnimation(out);

		ImageButton nextButton = (ImageButton) findViewById(R.id.next);
		nextButton.setBackgroundColor(Color.TRANSPARENT);
		nextButton.setOnClickListener(this);

		ImageButton backButton = (ImageButton) findViewById(R.id.back);
		backButton.setBackgroundColor(Color.TRANSPARENT);

		updateCounter();
	}

	public void onClick(View v) {
		mCounter++;
		updateCounter();
	}

	private void updateCounter() {
		mSwitcher.setText(String.valueOf(mCounter));
		if (mCounter == Allomasok.size())
		mCounter = 0;
		mSwitcherAllomasok.setText(Allomasok.get(mCounter));
		}
	*/
	// Button backB = (Button) findViewById(R.id.backB);
	// backB.setOnClickListener(new OnClickListener() {

	// public void onClick(View v) {
	// TODO Auto-generated method stub
	// startActivity(new Intent(
	// RoutesActivity.this,
	// SettingsActivity.class));
	// }
	// });

	public View makeView() {
		TextView t = new TextView(this);
		t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
		t.setTextSize(36);
		return t;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			startActivity(new Intent(RoutesActivity.this, ParamActivity.class));
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

	private void messageBox(String mess) {
		final AlertDialog alertDialog;
		alertDialog = new AlertDialog.Builder(this).create();

		alertDialog.setTitle("Uzenet");
		alertDialog.setMessage(mess);

		alertDialog.show();

	}

}
